import { http } from "@/utils/http/axios";
import { RequestEnum } from "@/enums/httpEnum";

/**
 * 获取公告列表
 */
export const getNoticeList = () => {
  return http.request({
    url: '/notice',
    method: RequestEnum.GET
  }, {
    isTransformResponse: false
  })
}

/**
 * 公告状态：已读
 * @param id
 */
export const noticeRead = (id) => {
  return http.request({
    url: `/notice/read/${id}`,
    method: RequestEnum.PUT
  })
}

/**
 * 添加公告
 * @param data
 */
export const addNotice = (data: {content, title}) => {
  return http.request({
    url: '/notice',
    method: RequestEnum.POST,
    data
  }, {
    isTransformResponse: false
  })
}

/**
 * 分页获取系统公告
 * @param pageNum
 * @param pageSize
 */
export const getNoticePage = ({pageNum, pageSize}) => {
  return http.request({
    url: `/notice/page/${pageNum}/${pageSize}`,
    method: RequestEnum.GET
  })
}

/**
 * 修改公告内容
 * @param id
 * @param data
 */
export const updateNotice = (id, data: {content, title}) => {
  return http.request({
    url: `/notice/${id}`,
    method: RequestEnum.PUT,
    data
  }, {
    isTransformResponse: false
  })
}

/**
 * 修改公告状态
 * @param id
 */
export const updateNoticeStatus = (id) => {
  return http.request({
    url: `/notice/status/${id}`,
    method: RequestEnum.PUT
  }, {
    isShowSuccessMessage: true
  })
}

/**
 * 删除公告
 * @param id
 */
export const deleteNotice = (id) => {
  return http.request({
    url: `/notice/${id}`,
    method: RequestEnum.DELETE
  }, {
    isShowSuccessMessage: true
  })
}
